﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.Utility;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Artech.EnterLibExt.ExceptionHandling.Configuration;

namespace Artech.EnterLibExt.ExceptionHandling
{
    [ConfigurationElementType(typeof(DomainFilterData))]
    public class DomainFilter: PropertyComparisonFilter
    {
        public bool IgnoreCase { get; private set; }
        public IEnumerable<string> Values { get; private set; }

        public DomainFilter(string propertyName, string values, bool ignoreCase):base(propertyName)
        {
            Guard.ArgumentNotNullOrEmpty(values, "values");
            this.Values = values.Split(',');
            this.IgnoreCase = ignoreCase;
        }

        public override bool Match(Exception ex)
        {
            string properyValue = this.GetPropertyValue(ex).ToString();
            return this.Values.Any(value=> string.Compare(properyValue,value,this.IgnoreCase) == 0);
        }
    }
}
